package com.geek.netty.demo.netty;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;

/**
 * @program netty-server
 * @description: handler
 * @author: chanzhugang
 * @create: 2021/08/16 19:13
 */
public class EchoServerHandler extends ChannelInboundHandlerAdapter {

    //处理读事件
    @Override public void channelRead (ChannelHandlerContext ctx, Object msg) {
        ctx.write(msg);
    }

    //处理读完成事件
    @Override public void channelReadComplete( ChannelHandlerContext ctx) {
        ctx.flush();
    }

    //处理异常事件
    @Override public void exceptionCaught( ChannelHandlerContext ctx, Throwable cause) {
        cause.printStackTrace();
        ctx.close();
    }
}